package com.example.getdata.task;

import ch.ethz.ssh2.Connection;
import com.example.getdata.properties.SSHProperty;
import com.example.getdata.properties.SSHPropertys;
import com.example.getdata.utils.SshUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("getDataTask")
public class RyTask
{
    @Autowired
    private SSHPropertys sshPropertys;

    public void getdata() throws Exception {
        //开启之前先关闭
        senddata();
        for (SSHProperty sshProperty : sshPropertys.getHost()) {
            //创建连接
            Connection login = SshUtil.login(sshProperty.getIp(), sshProperty.getPort(),
                    sshProperty.getUsername(), sshProperty.getPassword());
            if(login != null)
                SshUtil.execute(login,sshPropertys.getStartCmd());
        }

    }

    public void senddata() throws Exception {
        for (SSHProperty sshProperty : sshPropertys.getHost()) {
            //创建连接
            Connection login = SshUtil.login(sshProperty.getIp(), sshProperty.getPort(),
                    sshProperty.getUsername(), sshProperty.getPassword());
            if(login != null)
                SshUtil.execute(login, sshPropertys.getEndCmd());
        }
    }
}
